<?php
/**
 * Object Relational Persistence Mapping Class for table: sale_service_map.
 *
 * @package com.athena
 * @author  LHV
 */
$loader->requireOnce('ordo/Service.class.php');

class SaleServiceMap extends ORDataObject {
	const SALE_ITEM_TYPE = 'sale';

    /**#@+
     * Fields of table: sale_service_map mapped to class members
     */
    var $sale_service_map_id = '';
    var $sale_program_id = '';
    var $service_id = '';
    var $value = '';
    var $percent = '';
    var $item_type = '';
    /**#@-*/

    /**
     * DB Table
     */
    var $_table = 'sale_service_map';

    /**
     * Primary Key
     */
    var $_key = 'sale_service_map_id';
    
    /**
     * Internal Name
     */
    var $_internalName = 'SaleServiceMap';

    /**
     * Constructor.
     */
    function SaleServiceMap() {
        parent::ORDataObject();
    }
    /**
     * @author hdviet
     * modified for localizing others
     */
    function getServiceBySaleProgram($saleProId) {
        $field        =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');    	
	
    	$ds = new Datasource_sql();
        $sql = array(
            'cols'    => "s.service_id, s.$field as name, ssm.value, ssm.percent",
            'from'    => "sale_service_map ssm INNER JOIN service s ON ssm.service_id = s.service_id",
            'where'   => "ssm.sale_program_id=$saleProId AND ssm.item_type='" . self::SALE_ITEM_TYPE . "'" ,
            'orderby' => "name"
            );
        $ds->setup($this->_db, $sql);
        return $ds->toArray();
    }
    
    function deleteServiceOfSaleProgram($saleProId) {
    	$sql = "delete from $this->_table where sale_program_id = $saleProId";
        $this->_execute($sql);        
    }
    
}
?>